﻿namespace com.crownpack
{
    using System.Reflection;
    using System.Xml;

    using com.crownpack.Extensions.AssemblyExtensions;
    using com.crownpack.SharePoint;

    using Microsoft.SharePoint;

    public class CustomBaseDefinition : BaseDefinition
    {
        #region Constructors

        public CustomBaseDefinition( SPFeatureReceiverProperties properties )
            : base(properties)
        {
        }

        ~CustomBaseDefinition( )
        {
            Dispose( false );
        }

        #endregion Constructors

        #region Methods

        public override void Create( )
        {
            base.Create( );
        }

        public override void Delete( )
        {
            base.Delete( );
        }

        internal XmlNodeList GetFieldDefinitionsAsXml( string resource )
        {
            XmlNodeList fields = null;
            string s = Assembly.GetExecutingAssembly( ).GetFullyQualifiedManifestResourceName( resource );
            string xml = Assembly.GetExecutingAssembly( ).GetManifestResourceAsString( s );
            if ( !string.IsNullOrEmpty( xml ) )
            {
                XmlDocument d = new XmlDocument( );
                d.LoadXml( xml );
                XmlNode n = d.SelectSingleNode( "Fields" );
                fields = n.SelectNodes( "Field" );
            }
            return fields;
        }

        internal string GetViewSchemaAsXmlString( string resource )
        {
            string value = string.Empty;
            string s = Assembly.GetExecutingAssembly( ).GetFullyQualifiedManifestResourceName( resource );
            string xml = Assembly.GetExecutingAssembly( ).GetManifestResourceAsString( s );
            if ( !string.IsNullOrEmpty( xml ) )
            {
                XmlDocument d = new XmlDocument( );
                d.LoadXml( xml );
                XmlNode n = d.SelectSingleNode( "View" );
                value = n.OuterXml;
            }
            return value;
        }

        #endregion Methods
    }
}